<template>
    <div class="tabs">
        <el-tag v-for="(item, index) in tabList" :key="item.name" :closable="item.name !== 'home'"
            :effect="$route.name === item.name ? 'dark' : 'light'" @click="changeMenu(item)"
            @close="handleClose(item, index)">
            {{ item.label }}
        </el-tag>
    </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";
export default {
    computed: {
        ...mapState('tab', ['tabList'])
    },
    methods: {
        ...mapMutations("tab", ["closeTag"]),
        changeMenu(item) {
            this.$router.push({ name: item.name })
        },
        handleClose(item, index) {
            // 调用store中的mutation
            this.closeTag(item)
            const length = this.tabList.length - 1


        }
    }

}
</script>

<style lang="less" scoped>
.tabs {
    padding: 20px 20px 0;
    .el-tag{
        margin: 0 5px;
    }
}
</style>